package lyq.spec.edu.week10_class2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class FirstActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_activity);
        Button button1 = (Button) findViewById(R.id.button_1);  //findViewById方法获取布局文件定义元素
        button1.setOnClickListener(new View.OnClickListener() {  //setOnClickListener方法为按钮注册一个监听器，点击按钮时会执行监听器中的onClick方法
            @Override
            public void onClick(View v) {
                Toast.makeText(FirstActivity.this,"Hello FistActivity",Toast.LENGTH_SHORT).show();  //通过静态方法makeText创建一个Toast对象，然后调用show方法
                Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
                startActivity(intent);
            }
        });

    }

}
